package com.mistyrain.controller;

import com.mistyrain.entity.Menu;
import com.mistyrain.entity.MenuVO;
import com.mistyrain.service.MenuService;
import com.mistyrain.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/menu")
public class MenuHandler {

    @Autowired
    private MenuService menuService;
    @Autowired
    private OrderService orderService;

    @GetMapping("/findAll")
    @ResponseBody
    public MenuVO findAll(@RequestParam("page") int page, @RequestParam("limit") int limit){
        return menuService.findAll(page, limit);
    }

    @GetMapping("/prepareSave")
    public String prepareSave(Model model){
        return menuService.prepareSave(model);
    }

    @PostMapping("/save")
    public String save(Menu menu){
        return menuService.save(menu);
    }

    @GetMapping("/findById/{id}")
    public String findById(@PathVariable("id") long id,Model model){
        return menuService.findById(id,model);
    }

    @PostMapping("/update")
    public String update(Menu menu){
        return menuService.update(menu);
    }

    @GetMapping("/deleteById/{id}")
    public String deleteById(@PathVariable("id") long id){
       return menuService.deleteById(id);
    }
}
